 private static Bitmap CaptureScreen()
 {
     int screenWidth = Screen.PrimaryScreen.Bounds.Width;
     int screenHeight = Screen.PrimaryScreen.Bounds.Height;
     int screenX = Screen.PrimaryScreen.Bounds.X;
     int screenY = Screen.PrimaryScreen.Bounds.Y;
            
     Size boundsSize = Screen.PrimaryScreen.Bounds.Size;
     PixelFormat gfxFormat = PixelFormat.Format32bppArgb;
     Bitmap picture = new Bitmap(screenWidth, screenHeight, gfxFormat);
     Graphics graphics = Graphics.FromImage(picture);

     graphics.CopyFromScreen(screenX, screenY, 0, 0, boundsSize, CopyPixelOperation.SourceCopy);

     return picture;
 }